//
//  EnglishCollectionViewController.m
//  Education
//
//  Created by 流风幻雾 on 15/7/14.
//  Copyright (c) 2015年 HUA. All rights reserved.
//

#import "EnglishCollectionViewController.h"
#import "CollectionViewModel.h"
#import "EnglishCollectionViewCell.h"
#import "BackImageView.h"
@interface EnglishCollectionViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property(strong,nonatomic)UICollectionView *collectionView;
@property(strong,nonatomic)UICollectionViewFlowLayout *collectionViewFlowLayout;
@property(strong,nonatomic)CollectionViewModel *model;
@end

@implementation EnglishCollectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    BackImageView *backImage = [[BackImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.collectionViewFlowLayout = [[UICollectionViewFlowLayout alloc]init];
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) collectionViewLayout:_collectionViewFlowLayout];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.collectionView registerClass:[EnglishCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    self.model = [CollectionViewModel returnModel];
    self.collectionView.backgroundView = backImage;
    [self.view addSubview:_collectionView];

    
    
}

//返回item个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _model.imageArray.count;
}

//返回分区数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

//返回cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    EnglishCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    [cell setValueWithModel:self.model indexpath:indexPath];
    return cell;
}

//返回每个item大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(kScreenHeight * 0.22,kScreenWidth * 0.49);
}


//返回间距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(kScreenWidth * 0.02, kScreenWidth * 0.08, 0, kScreenWidth * 0.08);
}


//添加点击方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
